package com.moleq.service;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.moleq.db.DatabaseHelper;
import com.moleq.models.NetWT;

public class NetWTService {
	
	Context mContext;
	private DatabaseHelper DBHelper;
	private SQLiteDatabase db;

	public NetWTService(Context context) {
		this.DBHelper = new DatabaseHelper(context);
		this.mContext = context;
	}

	public NetWTService(String shareDBPath) {
		this.db = SQLiteDatabase.openOrCreateDatabase(shareDBPath, null);
	}

	public List<NetWT> FindNetWT() {
		db = DBHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(
				"select * from t_uom_desc order by UPPER(ud_desc)", null);
		List<NetWT> list = new ArrayList<NetWT>();
		int position = 0;
		while (cursor.moveToNext()) {
			NetWT item = new NetWT(cursor.getString(0), cursor.getString(1),
					cursor.getString(2), position);
			position++;
			list.add(item);
		}
		cursor.close();
		return list;
	}

	public List<NetWT> FindNetWT(String net_wt_search) {
		db = DBHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(
				"select * from t_uom_desc where ud_desc like '" + net_wt_search
						+ "%' order by ud_desc", null);
		List<NetWT> list = new ArrayList<NetWT>();
		int position = 0;
		while (cursor.moveToNext()) {
			NetWT item = new NetWT(cursor.getString(0), cursor.getString(1),
					cursor.getString(2), position);
			position++;
			list.add(item);
		}
		cursor.close();
		return list;
	}
}
